<template>
  <div class="dialog" v-show="visible" @click.self="$emit('update:visible',false)">
    <div class="dialog-container">
      <div class="dialog-header">
        <span class="dialog-title">{{ title }}</span>
        <button type="button" class="dialog-header-btn" @click="$emit('update:visible',false)">
          <div>X</div>
        </button>
      </div>
      <div class="dialog-body">
        <!-- 默认插槽 -->
        <slot />
      </div>
      <div class="dialog-footer">
        <!-- 具名插槽、命名插槽 -->
        <slot name="footer" />
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'

export default defineComponent({
  name: 'Login',
})
</script>

<script lang="ts" setup>
import {ref,watch,onBeforeUnmount} from 'vue';
const props=defineProps<{visible:boolean,title:string}>();
watch(()=>props.visible,()=>{
   if (props.visible) {
        document.documentElement.style.overflow = "hidden";
      } else {
        document.documentElement.style.overflow = "auto";
      }
})
onBeforeUnmount(()=>{
   document.documentElement.style.overflow = "auto";
})
</script>
<style lang="less">
.dialog {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 2001;
  background-color: rgba(0, 0, 0, 0.4);
}

.dialog-container {
  position: relative;
  margin: 30vh auto 50px;
  background: #fff;
  border-radius: 2px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
  box-sizing: border-box;
  width: 55%;
  height: 55%;
}

.dialog-header {
  padding: 20px 20px 10px;
  text-align: center;
   border-bottom: 1px solid #eaeaea
}
.dialog-title {
  line-height: 24px;
  font-size: 18px;
  color: #303133;
  text-align: center;
  font-weight: bold;
}
.dialog-header-btn {
  position: absolute;
  top: 20px;
  right: 20px;
  padding: 0;
  background: transparent;
  border: none;
  outline: none;
  cursor: pointer;
  font-size: 16px;
}
.dialog-body {
  padding: 30px 20px;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
  align-items: center;
  width: 497px;
}

.dialog-footer {
  padding: 10px 20px 20px;
  text-align: right;
  box-sizing: border-box;
}
</style>